import json

def getscore(a,b,lis,k,flag):
    if(a==b): return 0
    ra=0
    rb=0
    for team in lis:
        if a==team['name']:
            ra=team['score']
        if b==team['name']:
            rb=team['score']
    if(ra==0): return 0
    if(rb==0): return 0
    ea=1/1+pow(10,rb-ra)/400
    eb=1/1+pow(10,ra-rb)/400
    if(flag==1): dra=k*(1-ea)
    else: dra=k*(0-ea)
    return dra

def change(s):
    tms=[]
    for i in s: tms.append(i);
    with open('scorelist_team.json',encoding='utf-8')  as f:
        lis=json.loads(f.read())
    k=len(s)
    ch={}
    for i in s:
        ans=0
        for j in s:
            if s.index(i)<s.index(j): fl=1
            else: fl=0
            ans+=getscore(i,j,lis,k,fl);
        ch[j]=ans

    for i in s:
        for j in lis:
            if j['name']==i:
                j['score']+=ch['j']
    with open('scorelist_team.json',encoding='utf-8')  as f:
        f.write( json.dumps( lis, ensure_ascii=False ) )
    print(lis);

